﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Moki.Examples.Model;

namespace Moki.Examples
{
	[TestFixture]
	class MokiVerify
	{
		[Test]
		public static void Verify()
		{
			// Arrange
			IBookingDB database = Mock.Create<IBookingDB>();
			CinemaBookingService booking = new CinemaBookingService(database);

			Show show = new Show();

			// Act
			booking.BookPlace(show, 10, "Jan Kowalski");

			// Assert
			Mock.VerifyCalled(() => database.Book(show, 10, "Jan Kowalski"));

		}

		[Test]
		public static void VerifySetGet()
		{
			// Arrange
			IPerson person = Mock.Create<IPerson>();
			
			// Act

			// Set
			person.Name = "Julia"; 

			// Get
			string name = person.Name; 

			// Assert
			Mock.VerifySet(() => person.Name, "Julia");
			Mock.VerifyGet(() => person.Name);

		}

		[Test]
		public static void VerifyTimes()
		{
			// Arrange
			IBookingDB database = Mock.Create<IBookingDB>();
			CachedBookingDB cachedDatabase = Mock.Create<CachedBookingDB>(database);

			Show show = new Show();

			// Act
			for (int i = 0; i < 10; i++)
			{
				cachedDatabase.GetBooking(show, 10);
			}
		 
			// Assert
			Mock.VerifyCalled(() => cachedDatabase.GetBooking(show, 10), Times.Exactly(10));
			Mock.VerifyCalled(() => database.GetBooking(show, 10), Times.AtMost(1));
		}

	}
}
